<template>
	<view v-if="token!=null || token!=undefined">
		<view class="myu-demo">
			<components :is="mucomp" ></components>
		</view>
		<u-tabbar v-model="current" :list="list"></u-tabbar>
	</view>
</template>

<script>
	import home from '../../pages/home/home'
	import task from '../../pages/task/task'
	import msg from  '../../pages/msg/msg'
	import user from '../../pages/user/user'
	export default {
		components: {
			home,
			task,
			msg,
			user
		},
		data() {
			return {
				mucomp: "home",
				current: null,
				list: [{
						iconPath: "home",
						selectedIconPath: "home-fill",
						text: '首页',
						customIcon: false,
						mucomp: "home"
					},
					{
						iconPath: "file-text",
						selectedIconPath: "file-text-fill",
						text: '任务',
						customIcon: false,
						mucomp: "task"
					},
					{
						iconPath: "email",
						selectedIconPath: "email-fill",
						text: '消息',
						count: 0,
						isDot: false,
						customIcon: false,
						mucomp: "msg"
					},
					{
						iconPath: "account",
						selectedIconPath: "account-fill",
						text: '我的',
						customIcon: false,
						mucomp: "user"
					},
				],
				current: 0,
			}
		},
		watch: {
			current(val) {
				this.mucomp = this.list[val].mucomp
			},
			count(val){
				this.list[2].count = val
			},
				
		},
		computed: {
			publicMsg() {
				return this.$store.state.publicMsg
			},
			taskMsg(){
				return this.$store.state.taskMsg
			},
			count(){
				return (this.$store.state.taskMsg && this.$store.state.taskMsg.length) + 
				(this.$store.state.publicMsg && this.$store.state.publicMsg.length)
			},
			token() {
				return this.$store.state.token
			}
		},
		created() {
			this.list[2].count = this.count
		},
		onShow() {
			if (this.token == null || this.token == undefined) {
				this.$u.route("pages/login/login")
			}
		}

	}
</script>
<style>

</style>
